package com.coderush.admin.sys.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coderush.admin.core.common.MyBatisPlusPageUtils;
import com.coderush.admin.core.common.PageResult;
import com.coderush.admin.core.component.RedisClient;
import com.coderush.admin.core.utils.UserContext;
import com.coderush.admin.core.utils.UserContextModel;
import com.coderush.admin.sys.dao.EmployeeDao;
import com.coderush.admin.sys.model.dto.EmpSearchDto;
import com.coderush.admin.sys.model.dto.EmployeeAddDto;
import com.coderush.admin.sys.model.entity.Employee;
import com.coderush.admin.sys.model.vo.EmployeePageVo;
import com.coderush.admin.sys.service.EmployeeService;
import com.coderush.admin.sys.mapper.EmployeeMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description 针对表【sys_employee(员工信息表)】的数据库操作Service实现
 * @createDate 2025-08-18 10:21:09
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee>
        implements EmployeeService{

    @Resource
    private RedisClient redisClient;
    @Resource
    private EmployeeDao employeeDao;

    /**
     * 分页查询员工信息
     *
     * @param empSearchDto
     * @return
     */
    @Override
    public PageResult<EmployeePageVo> findByPage(EmpSearchDto empSearchDto) {

        // 构建分页对象
        Page<EmployeePageVo> page = MyBatisPlusPageUtils.buildPage(empSearchDto.getPageNumber(), empSearchDto.getPageSize());

        // 执行分页查询（会自动分页）
        Page<EmployeePageVo> usePage = employeeDao.findByPage(page, empSearchDto);

        // 将 MyBatis-Plus 的 IPage 转换为统一的 PageResult
        PageResult<EmployeePageVo> result = MyBatisPlusPageUtils.toPageResult(usePage);
        result.setList(usePage.getRecords());

        return result;
    }

    /**
     * 通过Token获取员工信息
     *
     * @return
     */
    @Override
    public UserContextModel getEmpInfo() {

        UserContextModel user = UserContext.getUser();

        return user;
    }

    /**
     * 添加员工信息
     * @param addDto
     */
    @Override
    public Boolean addEmpInfo(EmployeeAddDto addDto) {


        return true;
    }
}




